package com.neusoft.elm.service.impl;

import com.neusoft.elm.dao.UserDao;
import com.neusoft.elm.dao.impl.UserDaoImpl;
import com.neusoft.elm.po.User;
import com.neusoft.elm.service.UserService;
import com.neusoft.elm.util.DBUtil;

public class UserServiceImpl implements UserService {
    UserDao userDao = new UserDaoImpl();

    @Override
    public int saveUser(User user) throws Exception {
        try {
            //开启连接
            DBUtil.getConnection();
            int n = userDao.saveUser(user);
            return n;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            //关闭连接
            DBUtil.close();
        }
    }

    @Override
    public User getUserByIdByPass(String userId, String password) throws Exception {
        try {
            //开启连接
            DBUtil.getConnection();
            User user = userDao.getUserByIdByPass(userId, password);
            return user;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            //关闭连接
            DBUtil.close();
        }
    }

    @Override
    public User getUserById(String userId) throws Exception {
        try {
            //开启连接
            DBUtil.getConnection();
            User user = userDao.getUserById(userId);
            return user;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            //关闭连接
            DBUtil.close();
        }
    }
}
